
{extend name="User/index" /}
    {block name="users"}
        <div class="col-xs-12" style="margin-top: 20px;">
            <form class="form-horizontal" method="post" enctype="multipart/form-data">
                <table class="table table-striped">
                    <input type="hidden" value="{$data.id}" id="userid" name="id">
                    <tr>
                        <th>头像</th>
                        <td>
                            {if !empty($data['face'])}
                            <img src="/uploads/{$data.face}" class="userface"  width="80">
                            {elseif empty($data['face'])}
                            <img src="/static/mobile/image/face.png" class="userface" width="80">
                            {/if}
                            <input class="pull-right" style="width:180px;" type="file" name="face" id="face">
                        </td>
                    </tr>
                    <tr>
                        <th>姓名</th>
                        <td><input class="form-control" type="text" id="name" name="name" value="{$data.name}"></td>
                    </tr>
                    <tr>
                        <th>性别</th>
                        <td>
                            <label><input class="form-group-sm" {$data.sex == 0?'checked':''} type="radio" name="sex" value="0">女</label>
                            <label><input class="form-group-sm" {$data.sex == 1?'checked':''} type="radio" name="sex" value="1">男</label>
                        </td>
                    </tr>
                    <tr>
                        <th>邮箱</th>
                        <td><input class="form-control" type="text" name="email" value="{$data.email}" disabled></td>
                    </tr>
                    <tr>
                        <th>电话</th>
                        <td><input class="form-control" type="text" name="phone" value="{$data.phone}" disabled></td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <button class="form-control btn-success edit">修改资料</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>

        <script src="/static/index/js/jquery.min.js"></script>
<script src="/static/index/js/toastr.min.js"></script>
<link href="/static/admin/css/toastr.min.css" rel="stylesheet"/>

<script type="text/javascript">
    $(function(){
        $('.edit').click(function () {

            postdata();
        });
        function postdata(){
            //提交数据函数
            toastr.options = {
                closeButton: true,
                debug: false,
                progressBar: true,
                positionClass: "toast-top-right",
                onclick: null,
                showDuration: "2000",
                hideDuration: "1000",
                timeOut: "1000",
                extendedTimeOut: "1000",
                showEasing: "swing",
                hideEasing: "linear",
                showMethod: "fadeIn",
                hideMethod: "fadeOut"
            };
            // console.log(123);
            $.ajax({

                //调用jquery的ajax方法
                type: "POST",
                //设置ajax方法提交数据的形式
                url: "/mobile/User/update",
                //把数据提交到ok.php
                data: {
                    name : $("#name").val(),
                    sex: $("input:radio:checked").val()
                    // sex : $(".sex").val()
                },
                success: function(data){
                    if (data) {
                        // toastr.success('修改成功,2秒后跳转');
                        // setInterval(function(){
                            location.href='http://47.96.69.12/mobile/user/index';
                        // }, 2000);
                    }else{
                        toastr.error('您没有修改任何内容！');
                    }
                },
                error: function () {
                    alert('交互操作失败');
                }
            });
            return false;
        }

        //头像处理
        $('#face').change(function(){
            var formData = new FormData();
            var uid = $("#userid").val();
            formData.append("file",$("#face")[0].files[0]);
            formData.append("uid",uid);
            $.ajax({
                url: '/mobile/User/imgPath',
                type:'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function(data){
                    $('.userface').attr('src','/uploads/'+data.face);
                }
            })
        })
    })
</script>
    {/block}

